
#include<iostream>
#include<random>
#include<ctime>
#include<cstdlib>
#include<sys/types.h>
#include<unistd.h>
#pragma onece
void pullpak(){
    std::cerr << "开始拉取包-------" << std::endl;
}
void storage(){
    std::cerr << "存储包信息-------" << std::endl;
}
void provpak(){
    std::cerr << "验证包完整性------" << std::endl;
}
#define tasknum 3
typedef void(*f)();
static f task[3]={
        pullpak,
        storage,
        provpak
    };
void LoadTask(){
    srand(time(nullptr) ^ getpid() ^ 2343);
}

int SelectTask(){
    LoadTask();
    return rand() % tasknum;
}
void work(int rfd){
    while(true){
        sleep(1);
        int command = 0;
        int n = read(rfd, &command, sizeof(command));
        if(n == sizeof(int)){
            std::cerr << "Work:task[" << command << "]" << std::endl;
            task[command]();
        }
        else if(n == 0){//读端读到0，表示写端关闭
            std::cerr << "写端关闭，SubProcess:" << getpid() << "quit" << std::endl;
            break;
        }
    }
    
}